import { useMutation, useQuery } from "react-query";
import { useRequest } from "../utils/request";
import { IPage, IPageParams } from "../types";




/**
 * !获取全量角色接口
 * @returns 
 */
export const useGetSysRoleLiestAll = () => {
    const request = useRequest<ISysRole[]>();
    return useQuery(['sysRole'], () =>
        request('/sysRole/getSysRoleLiestAll', { data: {} }),
    );
};
/**
 * !搜索角色接口
 * @returns 
 */
export const useGetSysRoleSearch = (queryParams: ISysRoleSearchParams) => {
    const request = useRequest<IPage<ISysRole>>();
    return useQuery(['sysRole', queryParams], () =>
        request('/sysRole/getSysRoleBySearch', { data: queryParams }),
    );
};



/**
 * !删除角色
 */

export const useDeletedSysRoleById = () => {
    const request = useRequest<string>();
    return useMutation(async (params: { sysRoleId: number }) => {
        const result = request("/sysRole/deletedSysRoleById", {
            data: params,
            method: "DELETE",
        });
        return result;
    });
};

/**
 * !添加单位
 */
export const useAddSysRole = () => {
    const request = useRequest<string>();
    return useMutation(async (params: AddSysRoleType) => {
        const result = request("/sysRole/addSysRole", {
            data: params,
            method: "PUT",
        });
        return result;
    });
};

/**
 * !更新单位
 */

export const useUpdateSysRole = () => {
    const request = useRequest<string>();
    return useMutation(async (params: UpdateSysRoleType) => {
        const result = request("/sysRole/updateSysRole", {
            data: params,
            method: "POST",
        });
        return result;
    });
};


export type AddSysRoleType = {
    /**
     * 角色名称
     */
    sysRoleName: string;

    /**
    * 权限列表
    */
    sysRolePermisstion: string
}

export type UpdateSysRoleType = {
    sysRoleId: number;
} & Partial<AddSysRoleType>


/**
 * 搜索参数类型
 */
export type ISysRoleSearchParams = {
    sysRoleName: string;
} & IPageParams;

/**
 * 管理员基本类型
 */
export type ISysRole = {
    /**
    * 管理员角色ID
    */
    sysRoleId: number;

    /**
    * 角色名称
    */
    sysRoleName: string;

    /**
    * 权限列表
    */
    sysRolePermisstion: string
    /**
    * 创建时间
    */
    createTime: string;

    /**
    * 更新时间
    */
    updateTime: string
}